package com.google.appengine.echogear.jobs;

import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
import weibo4j.Weibo;

import com.google.appengine.echogear.core.EchoJob;

public final class TwitterJob extends EchoJob {

	private static final long serialVersionUID = -6022916155938171815L;
	
	Twitter twitter;
	Weibo weibo;

	public TwitterJob() {
		super();
	}

	@Override
	public boolean init() {
		try {
			String[] params = this.getParam().split(",");
			ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
			configurationBuilder
					.setDebugEnabled(true)
					.setOAuthConsumerKey(params[0])
					.setOAuthConsumerSecret(params[1])
					.setOAuthAccessToken(params[2])
					.setOAuthAccessTokenSecret(params[3]);
			TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
			twitter = twitterFactory.getInstance();
		} catch (Exception ex) {
			return false;
		}
		return true;
	}

	@Override
	public boolean send(String messgae) {
		try {
			twitter.updateStatus(messgae);
		} catch (Exception exception) {
			return false;
		}
		return true;
	}
}
